$(function() {
	doSearch();
});

function doSearch() {
	var startTime = $('#startTime').datebox('getValue');
	var endTime = $('#endTime').datebox('getValue');
	
	if (startTime != "" && endTime == "") {
		alert("请选择结束时间！");
	}
	if (startTime == "" && startTime != "") {
		alert("请选择开始时间！");
	}
	
	var issueNum = [];
	var executeNum = [];
	var totalNum = [];
	var syncNum = [];
	var rate = [];
	var totalRate = [];
	$.ajax({
		url : '/sdk/rate/listData',
		data : {
			startTime : startTime,
			endTime : endTime
		},
		type : "POST",
		datatype : "json",
		async : true,
		success : function(data) {
			var yAxis = eval(data.yAxis);
			$.each(yAxis, function(index, mod) {
				issueNum.push(mod.issueNum);
				executeNum.push(mod.executeNum);
				totalNum.push(mod.totalNum);
				syncNum.push(mod.syncNum);
				rate.push(mod.rate);
				totalRate.push(mod.totalRate);
			});
			showHighChart(data.xAxis, totalNum, issueNum, executeNum, rate, totalRate, syncNum);
		}
	});
}

function showHighChart (x, totalNum, issueNum, executeNum, rate, totalRate, syncNum) {
	Highcharts.chart('container', {
	    title: {
	        text: 'SDK执行率'
	    },
	    xAxis: {
	        categories: x
	    },
	    series: [{
	        type: 'column',
	        name: '获取短信',
	        data: totalNum
	    }, {
	        type: 'column',
	        name: '回传短信',
	        data: syncNum
	    }, {
	        type: 'column',
	        name: '实际下发量',
	        data: issueNum
	    }, {
	        type: 'column',
	        name: '执行量',
	        data: executeNum
	    }, {
	        type: 'spline',
	        name: '执行率',
	        data: rate,
	        marker: {
	            lineWidth: 2,
	            lineColor: Highcharts.getOptions().colors[3],
	            fillColor: 'white'
	        }
	    }, {
	        type: 'spline',
	        name: '下发率',
	        data: totalRate,
	        marker: {
	            lineWidth: 2,
	            lineColor: Highcharts.getOptions().colors[3],
	            fillColor: 'white'
	        }
	    }]
	});
}
